package com.lokiy.kit.ext

import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import com.lokiy.annotation.FragmentInfo
import kotlin.reflect.full.findAnnotation

/**
 *
 * @author Lokiy
 * @date 2023-08-04 17:22
 */
fun Fragment.setupToolbar(toolbar: Toolbar) {
    val requireActivity = requireActivity()
    if (requireActivity is AppCompatActivity) {
        requireActivity.setSupportActionBar(toolbar)
        toolbar.setNavigationOnClickListener {
            requireActivity.onBackPressedDispatcher.onBackPressed()
        }
        val title = this::class.findAnnotation<FragmentInfo>()?.value
        toolbar.title = title
        requireActivity.setTitle(title)
    }
}